<?php
class Plugin_Slide_Type extends Ot_Db_Table
{    
    public static function factory($plugin)
    {       
        $classname = $plugin . '_Module';
        
        set_include_path(
            get_include_path() . PATH_SEPARATOR . 
            self::getPluginPath()
        );
        
        /*
         * Load the adapter class.  This throws an exception
         * if the specified class cannot be loaded.
         */
        if (!class_exists($classname)) {
            require_once 'Zend/Loader.php';
            Zend_Loader::loadClass($classname);
        }
        
        $adapter = new $classname();
        
        /*
         * Verify that the object created is a descendent of the abstract adapter type.
         */
        if (!$adapter instanceof Plugin_Slide_Type_Interface) {
            throw new Exception("Plugin class '$classname' does not extend Plugin_Slide_Type_Interface");
        }

        return $adapter;
    }
    
    /**
     * gets the basepath to the plugin
     * 
     * @param $plugin
     * @return string
     */
    public static function getPluginPath($plugin = '')
    {
        return realpath(APPLICATION_PATH . '/../plugins/slidetype/' . $plugin);
    }
}